import axios from 'axios'
import base from './base'
import md5 from 'md5-js'
import jsonp from 'jsonp'

/**
 * 发请求的接口
 */
const api = {
    /**
     * 病毒信息获取
     */
    getCovInfo() {
        return axios.get(base.host + base.covInfo)
    },
    getChinaData() {
        return axios.get(base.baseUrl + base.chinaData)
    },
    getWorldData() {
        return axios.get(base.baseUrl + base.worldData)
    },
    getCityData(cityname) {
        let rule = md5(`appid16038city_name${cityname}formatjson470b94f145edafc593ffe2334c4ab291`)
        let canshu = 'format=json&city_name=' + cityname + '&appid=16008&sign=' + rule
        return axios.get(base.baseUrl + base.city + "?" + canshu);
    },
    getCovPic() {
        return axios.get(base.covPic)
    },
    getTravelCity() {
        return axios.get(base.travelCity)
    },
    getTravelQuery(params) {
        return axios.get(base.travelQuery, {
            params
        })
    },
    getTable(fn) {
        let res
        jsonp(base.tableUrl + base.tableDate, null, (err, data) => {
            // if (err) console.log(err)
            fn(data)
        })
    }
}

export default api